package me.leon.lib

import android.content.Context
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
class MockitoTest {
    //
    @Mock private lateinit var mMockContext: Context

    @Before
    fun setUp() {
        // 模拟方法调用的返回值，隔离对Android系统的依赖
        Mockito.`when`(mMockContext.getString(R.string.app_name)).thenReturn("Leon")
        Mockito.`when`(mMockContext.packageName).thenReturn("me.leon")
    }
    @Test
    fun readStringFromContext_LocalizedString() {

        assertThat(mMockContext.getString(R.string.app_name)).isEqualTo("Leon")

        // ...when the string is returned from the object under test...

        // ...then the result should be the expected one.
        assertThat(mMockContext.packageName).isEqualTo("me.leon")
    }
}
